package com.lst.api.vo;

import com.lst.api.constant.BuyTypeEnum;
import com.lst.api.entity.AssetsHouseInfo;
import com.lst.api.exception.RequestParamErrorException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * 资产信息中的房产信息
 *
 * @author Frank
 * @date 2019-12-30 10:31:37
 * @version: V1.0
 */
@Data
@NoArgsConstructor
public class AssetsHouseInfoVo implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "addressProvinceCode", value = "房产地址，省编号", required = true, dataType = "String")
    private String addressProvinceCode;

    @ApiModelProperty(name = "addressCityCode", value = "房产地址，市编号", required = true, dataType = "String")
    private String addressCityCode;

    @ApiModelProperty(name = "addressAreaCode", value = "房产地址，区编号", required = true, dataType = "String")
    private String addressAreaCode;

    @ApiModelProperty(name = "addressDetails", value = "房产地址，详细地址", required = true, dataType = "String")
    private String addressDetails;

    @ApiModelProperty(name = "owner", value = "共有人", required = true, dataType = "String")
    private String owner;

    @ApiModelProperty(name = "buyType", value = "购房方式    0:一次性    1:按揭", required = true, dataType = "String")
    private String buyType;

    @ApiModelProperty(name = "totalLoanAmount", value = "贷款总额,单位元", dataType = "Double")
    private Double totalLoanAmount;

    @ApiModelProperty(name = "monthlySupply", value = "月供，单位元", dataType = "Double")
    private Double monthlySupply;

    @ApiModelProperty(name = "loanBankId", value = "贷款银行id", dataType = "Long")
    private Long loanBankId;

    @ApiModelProperty(name = "loanYears", value = "贷款年限，单位年", dataType = "Integer")
    private Integer loanYears;

    @ApiModelProperty(name = "buyTotalAmount", value = "购买总金额", required = true, dataType = "Double")
    private Double buyTotalAmount;

    @ApiModelProperty(name = "buildArea", value = "建筑面积，单位平方米", required = true, dataType = "Double")
    private Double buildArea;

    @ApiModelProperty(name = "totalHouse", value = "房产总数", required = true, dataType = "Integer")
    private Integer totalHouse;

    public AssetsHouseInfoVo(AssetsHouseInfo assetsHouseInfo) {
        if (assetsHouseInfo == null) {
            return;
        }
        this.addressProvinceCode = assetsHouseInfo.getAddressProvinceCode();
        this.addressCityCode = assetsHouseInfo.getAddressCityCode();
        this.addressAreaCode = assetsHouseInfo.getAddressAreaCode();
        this.addressDetails = assetsHouseInfo.getAddressDetails();
        this.owner = assetsHouseInfo.getOwner();
        this.buyType = assetsHouseInfo.getBuyType();
        this.totalLoanAmount = assetsHouseInfo.getTotalLoanAmount();
        this.monthlySupply = assetsHouseInfo.getMonthlySupply();
        this.loanBankId = assetsHouseInfo.getLoanBankId();
        this.loanYears = assetsHouseInfo.getLoanYears();
        this.buyTotalAmount = assetsHouseInfo.getBuyTotalAmount();
        this.buildArea = assetsHouseInfo.getBuildArea();
        this.totalHouse = assetsHouseInfo.getTotalHouse();
    }

    public void check() {
        boolean check = StringUtils.isNotBlank(this.addressProvinceCode)
                && StringUtils.isNotBlank(this.addressCityCode)
                && StringUtils.isNotBlank(this.addressAreaCode)
                && StringUtils.isNotBlank(this.addressDetails)
                && StringUtils.isNotBlank(this.owner)
                && BuyTypeEnum.getByKey(this.buyType) != null
                && this.buyTotalAmount != null
                && this.buildArea != null
                && this.totalHouse != null;
        if (check && BuyTypeEnum.MORTGAGE.getKey().equals(this.buyType)) {
            check &= totalLoanAmount != null
                    && monthlySupply != null
                    && loanBankId != null
                    && loanYears != null;
        }
        if (!check) {
            throw new RequestParamErrorException("AssetsHouseInfoVo请求参数不合法！");
        }
    }
}